using UnityEngine;
using System.Collections;

public class UnlockAchieve_PrefabSc : MonoBehaviour {

	public float lifeTime;
	public UI_TextMessage Title;
	public UI_TextMessage Subtitle;
	private bool hasNext;
	private AchievementItem ach;
	private Transform UnlockAchieve_Prefab;
	private UnlockAchieve_PrefabSc lastName;
	void Start() 
	{
		StartCoroutine( Example(lifeTime));
	}
	
	IEnumerator Example(float seconds)
    {
        yield return new WaitForSeconds(seconds);
			Destroy(gameObject);
		gameObject.tag = null;
		if(hasNext)
		{
			Camera cam = Camera.mainCamera;
			Vector3 pos = new Vector3(cam.transform.position.x , cam.transform.position.y - 5 , -9.873669f);
			Instantiate(this.UnlockAchieve_Prefab, pos, UnlockAchieve_Prefab.transform.rotation);
			GameObject unlockPrefab = GameObject.FindGameObjectWithTag("Achievement");
			unlockPrefab.transform.parent = cam.transform;
						
			UnlockAchieve_PrefabSc script = unlockPrefab.GetComponent<UnlockAchieve_PrefabSc>();
			ach.SetCompleted();
			script.SetAchieve(ach,script);
		}
		
	}
	
	void NextDelete(AchievementItem ach)
	{
		this.ach = ach;
		hasNext = true;
	}
	void receivedPrefab(Transform prefab)
	{
		UnlockAchieve_Prefab = prefab;
	}
	
	public void SetAchieve(AchievementItem ach,UnlockAchieve_PrefabSc scr)
	{	
		scr.Title.gameObject.SendMessage("addId",ach.titleId,SendMessageOptions.RequireReceiver);
		scr.Subtitle.gameObject.SendMessage("addId",ach.subtitleId,SendMessageOptions.RequireReceiver);
	}
	
	
}
